home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - Mac PPC / doc / streams.txt < prev    next >
Encoding:
Text File  |  1995-03-15  |  68.1 KB  |  1,704 lines  |  [TEXT/MMCC]

  1. [NOTE: This file has been generated by a series of translation tools that
  2.  converted an original FrameMaker .mif file to this .txt file.  The
  3.  conversion tools created the table of contents and uppercased all
  4.  identifiers.  The printed representation of all identifiers in this
  5.  interface is lowercase.  The conversion tools also sometimes drops hyphens
  6.  from identifiers, so if you think a name should have a hyphen in it, it
  7.  probably does.  It is not worth the effort to manually fix this .txt file
  8.  to correct these problems.]
  9.  
  10.  
  11.                           GWYDION STREAMS FOR DYLAN
  12.                           =========================
  13.  
  14. Designed by the Gwydion Project
  15.  
  16. Version 3.1 :
  17.  
  18. ------------------------------------------------------------------------------
  19.  
  20. Table of Contents
  21. -----------------
  22.  
  23. 1.  Overview
  24.  
  25.     1.1.  Classes
  26.  
  27.     1.2.  Functions
  28.  
  29.     1.3.  Buffers
  30.  
  31.     1.4.  Usage Models
  32.  
  33.     1.5.  Characters
  34.  
  35.     1.6.  Locking
  36.  
  37.     1.7.  Miscellaneous Features
  38.  
  39. 2.  Classes and Other Types
  40.  
  41. 3.  Constants
  42.  
  43. 4.  The <stream> Protocol
  44.  
  45.     4.1.  Basic I/O Protocol
  46.  
  47.     4.2.  Data Extension Protocol
  48.  
  49.     4.3.  Buffer Access Protocol
  50.  
  51.     4.4.  Stream Extension Protocol
  52.  
  53. 5.  The <random-access-stream> Protocol
  54.  
  55. 6.  The <file-stream> Protocol
  56.  
  57. 7.  The <string-input-stream> Protocol
  58.  
  59. 8.   The <string-output-stream> Protocol
  60.  
  61. 9.  The <buffer> Protocol
  62.  
  63. 10.  Locking Protocol
  64.  
  65. 11.  Conditions
  66.  
  67. 12.  Footnotes
  68.  
  69. ------------------------------------------------------------------------------
  70.  
  71. This document describes the Streams library designed by the Gwydion Project
  72. at Carnegie Mellon University. The primary goals of this stream interface
  73. are efficiency, simplicity, and the ability to extend the stream protocol to
  74. more complex stream objects and more complex data objects. The stream design
  75. focuses on byte-oriented, buffered input and output. Implementations and
  76. users have access to the internal buffers of streams for efficiency reasons.
  77. Implementations and users can extend the stream protocol to a new stream
  78. subclass just by extending the interface to the stream `s buffer.
  79.  
  80. The Streams library contains none of the following kinds of functionality:
  81.  
  82.   * complex stream subclasses implementing streams such as concatenated,
  83.     broadcast, echo, two-way conglomerate, and so on.
  84.   * formatted output, such as Common Lisp's format function or C's printf.
  85.   * formatted input, such as C's scanf.
  86.   * so called readable printing, such as Common Lisp's print function.
  87.   * parsing, such as Common Lisp's read function.
  88.   * output and input of arbitrary binary representations, such as dumping
  89.     integers and floats in raw, implementation-dependent form.
  90.   * streams that do not support the stream protocol entirely; for example, a
  91.     record-oriented stream may not be able to support the read-byte
  92.     function.
  93.  
  94. Most of these items fit naturally on top of the Streams library, but
  95. regardless of that, separate libraries should provide the kinds of
  96. functionality listed above.
  97.  
  98. 1.  Overview
  99. ------------
  100. This section introduces some underlying concepts of the Streams library and
  101. provides a sketch of the required stream classes and functions. The Streams
  102. library exports at least one module, the Streams module, and it is this
  103. module that exports all of the definitions described in this document.
  104.  
  105. 1.1.  Classes
  106.  
  107. The following classes are required (indentation shows subclass
  108. relationship):
  109.  
  110.    <stream> [Abstract]
  111.       <random-access-stream> [Abstract]
  112.          <string-input-stream> [Abstract]
  113.             <byte-string-input-stream> [Concrete]
  114.          <string-output-stream> [Abstract]
  115.             <byte-string-output-stream> [Concrete]
  116.       <file-stream> [Abstract Instantiable]
  117.  
  118. Implementations are required to provide a concrete class that is a subclass
  119. of <random-access-stream> and <file-stream>, and when users call the make
  120. function on <file-stream>, they get an instance o f this
  121. implementation-dependent concrete class.
  122.  
  123. 1.2.  Functions
  124.  
  125. This subsection sketches the functions exported from the Streams module.
  126. This is not a complete list of applicable functions; for example, make is
  127. not listed for any class, and sequence operations are not listed for the
  128. <buffer> class.
  129.  
  130. The following functions comprise the Basic I/O Protocol (described in
  131. Section The <stream> Protocol):
  132.  
  133.     READ-BYTE
  134.     PEEK-BYTE
  135.     READ-LINE
  136.     INPUT-AVAILABLE?
  137.     FLUSH-INPUT
  138.     FORCE-OUTPUT
  139.     SYNCHRONIZE-OUTPUT
  140.  
  141. The following functions comprise the Data Extension Protocol (described in
  142. Section The <stream> Protocol):
  143.  
  144.     READ-AS
  145.     READ-INTO!
  146.     WRITE
  147.     WRITE-LINE
  148.  
  149. The following functions comprise the Random Access Protocol (described in
  150. Section The <random-access-stream> Protocol):
  151.  
  152.     STREAM-POSITION
  153.     STREAM-POSITION-SETTER
  154.     ADJUST-STREAM-POSITION
  155.     STREAM-SIZE
  156.  
  157. The following function comprises the <string-output-stream> protocol
  158. (described in Section The <string-output-stream> Protocol):
  159.  
  160.     STRING-OUTPUT-STREAM-STRING
  161.  
  162. The following functions comprise the Buffer Access Protocol (described in
  163. Section The <stream> Protocol):
  164.  
  165.     GET-INPUT-BUFFER
  166.     RELEASE-INPUT-BUFFER
  167.     FILL-INPUT-BUFFER
  168.     INPUT-AVAILABLE-AT-SOURCE?
  169.     GET-OUTPUT-BUFFER
  170.     RELEASE-OUTPUT-BUFFER
  171.     EMPTY-OUTPUT-BUFFER
  172.     FORCE-SECONDARY-BUFFERS
  173.     SYNCHRONIZE
  174.  
  175. The following functions comprise the Stream Extension Protocol (described in
  176. Section The <stream> Protocol):
  177.  
  178.     CLOSE
  179.     STREAM-EXTENSION-GET-INPUT-BUFFER
  180.     STREAM-EXTENSION-RELEASE-INPUT-BUFFER
  181.     STREAM-EXTENSION-FILL-INPUT-BUFFER
  182.     STREAM-EXTENSION-INPUT-AVAILABLE-AT-SOURCE?
  183.     STREAM-EXTENSION-GET-OUTPUT-BUFFER
  184.     STREAM-EXTENSION-RELEASE-OUTPUT-BUFFER
  185.     STREAM-EXTENSION-EMPTY-OUTPUT-BUFFER
  186.     STREAM-EXTENSION-FORCE-SECONDARY-BUFFERS
  187.     STREAM-EXTENSION-SYNCHRONIZE
  188.  
  189. The following functions comprise the <buffer> protocol (described in Section
  190. The <buffer> Protocol):
  191.  
  192.     BUFFER-SUBSEQUENCE
  193.     COPY-FROM-BUFFER!
  194.     COPY-INTO-BUFFER!
  195.  
  196. The following functions comprise the Locking Protocol (described in Section
  197. The Locking Protocol):
  198.  
  199.     lock-stream
  200.     unlock-stream
  201.     stream-locked?
  202.  
  203. 1.3.  Buffers
  204.  
  205. The Streams module provides the framework for defining various high-level
  206. streams, such as Common Lisp has. As stated previously, one of the primary
  207. goals of this stream interface is efficiency. The design of Common Lisp
  208. streams is inherently inefficient. For example, in Common Lisp if you have a
  209. general output routine for writing multiple items (or multiple components of
  210. an object) to a stream, you pay a big penalty in having to perform generic
  211. function invocation in the middle of your loop (or over a sequence of stream
  212. operations). This is because you cannot know until run time what sort of
  213. stream you have.
  214.  
  215. This stream interface solves this problem by providing a clean protocol for
  216. directly manipulating the internal buffers of streams. Since all streams
  217. have internal buffers that are instances of the same class, users can write
  218. efficient, stream-independent output routines by operating on the streams'
  219. buffers. Buffer methods can be fully determined at compile time. A Buffer is
  220. an instance of the <buffer> class, which is a sealed subclass of <vector>.
  221. Buffers have element type <byte> (see Subsection Miscellaneous Definitions
  222. for type definitions).
  223.  
  224. When users manipulate buffers directly, they are entirely responsible for
  225. maintaining the buffer's state. Once a user gets a stream's buffer, the
  226. stream object has no means to track activity in the buffer. To use a
  227. stream's buffer, users must explicitly get the buffer. At this time, the
  228. stream indicates where the pending input or output is in the buffer. If the
  229. stream is an input stream, users can consume as much of the pending input as
  230. necessary, filling the buffer with input from the stream's source any number
  231. of times, including none. If the stream is an output stream, users can store
  232. as much pending output in the buffer as necessary, forcing out the output
  233. any number of times, including none. When users are done with a stream's
  234. buffer, they must explicitly release the buffer and indicate to the stream
  235. the buffer's current state.
  236.  
  237. Stream implementations are required to be able to determine when an
  238. application is explicitly using a stream's buffer. Between the time when an
  239. application explicitly gets a stream's buffer and then later releases the
  240. buffer, the application is said to hold the buffer. Many routines in the
  241. stream interface are defined to only work correctly when the application
  242. holds the stream's buffer. These routines are defined, with respect to
  243. guaranteeing correct behavior and blocking behavior, to allow
  244. implementations freedom to provide safe and good development environment
  245. support and to provide good support for stream implementations in
  246. multi-threaded execution environments. See Subsections Stream Extension
  247. Protocol and Buffer Access Protocol.
  248.  
  249. When applications do not hold a stream's buffer, they cannot make any
  250. assumptions about the maintenance of the buffer. In particular, it is an
  251. error to save references to buffers, perform operations on buffers when not
  252. holding them (such as element-setter), and so on.
  253.  
  254. 1.4.  Usage Models
  255.  
  256. The Streams library supports three styles of usage. The first, and probably
  257. most common, is a simple style that uses high-level input and output
  258. functions, such as read-byte, read-as, write, and so on. The simple style
  259. will be the least efficient, but it provides convenience and is generally
  260. useful. In the second style, applications use the internal buffers of
  261. streams to grab multiple bytes of input at once or to provide multiple bytes
  262. of output at once. Using the buffers is relatively efficient, less
  263. convenient for the programmer, but generally just as useful as the simple
  264. style. In the third style, applications directly allocate buffers and use
  265. them for reading and writing very large chunks of data, probably whole files
  266. at once. Directly using buffers separately from the internal buffers of
  267. streams provides the greatest efficiency and is slightly less complicated
  268. than the second style of usage; however, the third style has very specific
  269. uses and does not mix well with the first style.
  270.  
  271. The second style of usage is quite flexible. Users can mix the first and
  272. second styles of usage. Though users must explicitly get and release buffers
  273. to use buffers directly, when the buffers are not held, simple style input
  274. and output integrates smoothly with input read from and output placed in
  275. buffers directly. The second style of usage also provides more precise
  276. control over blocking behavior for some operations that are logically
  277. equivalent in the two styles.
  278.  
  279. Implementations should support the third style of usage without any
  280. unnecessary inefficiencies, such as double buffering. The Streams library
  281. provides functions such as read-into! and write that should have method that
  282. allow users to very efficiently fill a large buffer from a stream's source
  283. or deliver a large buffer to a stream's destination.
  284.  
  285. 1.5.  Characters
  286.  
  287. Because international character standards and file formats are still
  288. converging on a clear winner, this stream interface specifies very little
  289. about characters. Implementors are required to provide a subclass of
  290. <character> called <bytecharacter> and methods specialized on this class for
  291. the read-as and write generic functions. The <byte-character> class
  292. represents the ASCII character set (or extensions to ASCII). The Streams
  293. library requires support for ASCII characters because they capture a large
  294. portion of character I/O, and their use should be standard. Implementations
  295. are free to support other characters, and their support can naturally fit
  296. into the Streams library.
  297.  
  298. 1.6.  Locking
  299.  
  300. The Streams library provides two mutual exclusion mechanisms, the Buffer
  301. Access Protocol and the Locking Protocol. The Locking Protocol isolates
  302. access to a stream so that only one thread may use the stream at one time,
  303. and in a singlethreaded Dylan implementation, these functions do nothing.
  304. The Buffer Access Protocol isolates access to a buffer within a single
  305. thread, and applications use these functions regardless of whether the Dylan
  306. implementation is multithreaded. The Buffer Access Protocol functions that
  307. get a buffer first lock the stream, and those functions that release the
  308. buffer unlock the stream. Thus, getting a buffer both isolates access to the
  309. stream for a single thread and ensures that the single thread does not try
  310. to get the stream's buffer multiple times while already holding the buffer.
  311.  
  312. Stream locks have multilocking semantics. A single thread may repeatedly
  313. lock a particular stream, but that thread must unlock the stream once for
  314. each time it locked the stream. This allows a high-level printing routine to
  315. lock a stream across several calls to output functions, ensuring all the
  316. output is contiguous at the stream's destination. For example, the
  317. write-line function locks its stream argument and then calls the write
  318. function twice. The write function locks its stream argument by calling
  319. get-output-buffer, but because of the multilocking semantics, the call to
  320. write within write-line does not block waiting for a lock. Before returning,
  321. write-line unlocks the stream so that other routines may call output
  322. functions on the stream or get the stream's buffer for direct manipulation.
  323.  
  324. The Buffer Access Protocol isolates access to a buffer within a single
  325. thread to prevent reentrancy problems and programming mistakes. Essentially,
  326. the lightweight buffer locking ensures that applications do not call output
  327. functions that directly manipulate a stream's buffer from within routines
  328. that are already directly manipulating the stream's buffer. This situation
  329. must be forbidden because the inner call to get the buffer cannot reliably
  330. return the state of the stream's buffer while the application already holds
  331. the buffer.
  332.  
  333. 1.7.  Miscellaneous Features
  334.  
  335. The Streams library provides streams that support input operations, streams
  336. that support output operations, and streams that support both. The kind of
  337. operations supported by a particular stream is determined by keywords
  338. supplied when making the stream (such as with <file-stream> instances) or by
  339. the class of the stream (such as with <string-input-stream>).
  340. Implementations of output streams should arrange to have the Dylan run-time
  341. system force output when an application exits, but portable programs do not
  342. rely on this feature.
  343.  
  344. When opening is applicable, users open a stream by calling make on a stream
  345. class. The initialization protocols for the different subclasses of <stream>
  346. take keyword arguments that are appropriate to each subclass. The make
  347. function returns an open stream object. Unless otherwise specified, it is an
  348. error to use stream operations on closed streams.
  349.  
  350. When describing the stream protocol relating to buffers, this document uses
  351. the term end to discuss the end of valid data in buffers. The use of end is
  352. always an exclusive end of the data, that is, the buffer's element indicated
  353. by an end value is never part of the valid data. An end value may not be a
  354. valid buffer index; because Dylan sequences have zero-based indexes, an end
  355. value may be equal to the size of the buffer.
  356.  
  357. This document declares some arguments and return values to have the type
  358. <boolean>. This is not part of Dylan, and the Streams library does not
  359. export it. As used in this document, it has the following definition:
  360.  
  361.    union(singleton(#t), singleton(#f))
  362.  
  363. This document declares some arguments and return values to have the type
  364. <fixed-integer> to designate an implementation-dependent, finite integer
  365. type. The intent is that these integers are known to be small, lightweight
  366. integers (and will never be infinite precision integers).
  367.  
  368. 2.  Classes and Other Types
  369. ---------------------------
  370. The Streams module exports the following classes:
  371.  
  372. <stream>  [Abstract Class]
  373.  
  374.         This class is a subclass of <object>. All streams inherit from this
  375.         class. Make of <stream> subclasses accepts a size: keyword argument
  376.         that indicates the user's choice for a buffer size. Users must check
  377.         the size of the stream's buffer because implementations may ignore
  378.         the size: argument.
  379.  
  380. <random-access-stream>  [Abstract Class]
  381.  
  382.         This class is a subclass of <stream>. All required streams in the
  383.         Streams library inherit from this class, which means they support
  384.         the Random Access Protocol. Some implementations may provide streams
  385.         that do not inherit from this class (for example, a UnixTM SOCKET
  386.         STREAM).
  387.  
  388. <file-stream>  [Abstract Instantiable Class]
  389.  
  390.         This class is a subclass of <stream>. When users instantiate this
  391.         class, they get an implementation-dependent indirect instance that
  392.         is both a <file-stream> and a <random-access-stream>. See Section
  393.         The <file-stream> Protocol for the details of making these streams.
  394.  
  395. <string-input-stream>  [Abstract Class]
  396.  
  397.         This class is a subclass of <random-access-stream>. Make of
  398.         <string-input-stream> subclasses requires a string: keyword argument
  399.         that is an instance of <string>, and input operations on these
  400.         streams read from the supplied string.
  401.  
  402. <bye-string-input-stream>  [Concrete Class]
  403.  
  404.         This class is a subclass of <string-input-stream>. The string:
  405.         argument to make must be a <byte-string>.
  406.  
  407. <string-output-stream>  [Abstract Class]
  408.  
  409.         This class is a subclass of <random-access-stream>. These streams
  410.         collect their output, and when requested, they return the output as
  411.         a <byte-string>.
  412.  
  413. <byte-string-output-stream>  [Concrete Class]
  414.  
  415.         This class is a subclass of <string-output-stream>.
  416.  
  417. <byte-character>  [Type]
  418.  
  419.         This type is a subtype of <character>. Characters of this type
  420.         represents the ASCII character set (or extensions to ASCII).
  421.  
  422. <buffer>  [Concrete Class]
  423.  
  424.         This class is a sealed subclass of <vector>. These are the buffers
  425.         used by every general instance of <stream>. The element type of
  426.         buffers is <byte>.
  427.         The <buffer> class appears to the user to be semantically the same
  428.         as the <byte-vector> class, but implementors of the Streams library
  429.         may make use of internal systems storage or other internal features.
  430.         For example, an implementation might make buffers more suitable for
  431.         directly passing them to system calls or for maintaining interior
  432.         pointers into buffers, but users will be unaware o f any such
  433.         implementation tactics.
  434.  
  435. <buffer-index>  [Type]
  436.  
  437.         This is the type of values used to index buffers.
  438.  
  439. <byte>  [Type]
  440.  
  441.         This type represents limited integers: limited(<integer>, min: 0,
  442.         max: 255).
  443.  
  444. <byte-vector>  [Concrete Class]
  445.  
  446.         This class is a sealed subclass of <vector>. The element type of
  447.         byte-vectors is <byte>.
  448.  
  449. 3.  Constants
  450. -------------
  451. The Streams module exports the following constants:
  452.  
  453. $maximum-buffer-size  [Constant]
  454.  
  455.         This constant holds the maximum size: argument that users can supply
  456.         when making buffers and streams.
  457.  
  458. 4.  The <stream> Protocol
  459. -------------------------
  460. The <stream> protocol categorizes operations into five groups. This section
  461. discusses four of those groups:
  462.  
  463.     Basic I/O Protocol
  464.         Functions implemented on top of the Stream Extension Protocol. Users
  465.         should not need to add methods to the Basic I/O Protocol functions
  466.         when they define new stream subclasses.
  467.     Data Extension Protocol
  468.         Generic functions that are specialized to return or accept various
  469.         classes of objects when reading or writing. Implementations are
  470.         required to provide sealed methods for a few classes of data
  471.         objects. Implementations are free to forgo methods for many classes
  472.         of objects, and there may not even be a default method for <object>.
  473.         The Data Extension Protocol typically specializes methods based on
  474.         the classes of data objects returned by reading or accepted for
  475.         writing. Sometimes these functions need to specialize on the stream
  476.         as well as the data; for example, to most efficiently deliver a
  477.         buffer to an output stream's destination, a method may need to be
  478.         specific to a stream.
  479.     Buffer Access Protocol
  480.         Functions implemented on top of the Stream Extension Protocol. These
  481.         provide the means for users to get and release streams' buffers.
  482.         Users should never define new methods for these functions.
  483.     Stream Extension Protocol
  484.         Generic functions that anyone can use to extend the stream protocol
  485.         to new subclasses of streams. Implementations are required to have
  486.         sealed methods for this group's functions on the standard stream
  487.         subclasses.
  488.  
  489. The fifth group is the Locking Protocol (see Section The Locking Protocol).
  490.  
  491. 4.1.  Basic I/O Protocol
  492.  
  493. This subsection of the <stream> protocol describes the Basic I/O Protocol.
  494. Users should not need to add methods to the Basic I/O Protocol functions
  495. when they define new stream subclasses. The reading and writing functions
  496. primarily only operate on bytes. This subsection describes the following
  497. functions:
  498.  
  499.     READ-BYTE
  500.     PEEK-BYTE
  501.     READ-LINE
  502.     INPUT-AVAILABLE?
  503.     FLUSH-INPUT
  504.     FORCE-OUTPUT
  505.     SYNCHRONIZE-OUTPUT
  506.  
  507. read-byte  [Function]
  508.  
  509.     Arguments
  510.         stream :: <stream>
  511.         #key signal-eof? :: <boolean> = #t
  512.     Values
  513.         byte :: union(<byte>, singleton(#f))
  514.     Description
  515.         Returns one byte from stream. This function blocks until input is
  516.         available.  If reading from stream encounters the end of the stream,
  517.         then the signal-eof? argument determines the behavior of this
  518.         function. If signal-eof? is #t (the default), then this function
  519.         signals an <end-of-file> condition (see Section Conditions);
  520.         otherwise, this function returns #f.
  521.  
  522. peek-byte   [Function]
  523.  
  524.     Arguments
  525.         stream :: <stream>
  526.     values
  527.         byte :: union(<byte>, singleton(#f))
  528.     Description
  529.         Returns the next byte in the input without advancing the stream's
  530.         position. This function blocks until input is available. If reading
  531.         from stream encounters the end of the stream, then this function
  532.         returns #f.
  533.  
  534. read-line  [Function]
  535.  
  536.     Arguments
  537.         stream :: <stream>
  538.         #key signal-eof? :: <boolean> = #t
  539.     Values
  540.         line :: union(<string>, singleton(#f))
  541.         eof? :: <boolean>
  542.     Description
  543.         Returns as a <byte-string> all the input to the next newline
  544.         character.1 THE RESULTING STRING EXCLUDES THE NEWLINE CHARACTER.
  545.         THIS ROUTINE BLOCKS UNTIL IT ENCOUNTERS A NEWLINE OR THE END OF THE
  546.         STREAM'S SOURCE.  AS A SECOND VALUE, THIS FUNCTION RETURNS A BOOLEAN
  547.         TO INDICATE WHETHER THE LINE TERMINATED WITH THE END OF THE STREAM'S
  548.         SOURCE (#T) OR A NEWLINE (#F).
  549.  
  550.         Whenever a call to read-line encounters the end of stream's source
  551.         immediately (that is, there is no input to read), then the
  552.         signal-eof? argument determines the behavior of this function. In
  553.         this situation, if signal-eof? is #t (the default), then this
  554.         function signals an <end-of-file> error; otherwise, it returns #f
  555.         and #t as multiple values.
  556.  
  557. input-available?  [Function]
  558.  
  559.     Arguments
  560.         stream :: <stream>
  561.     Values
  562.         input-available? :: <boolean>
  563.     Description
  564.         Returns #t when stream has available input or when the stream is at
  565.         the end of its source.  If this function returns #t, then the next
  566.         call to read-byte will not block.  Note, though the next call to
  567.         read-byte will not block, read-byte will signal an <end-of-file>
  568.         condition (or return #f) if the stream is at the end of its source.
  569.  
  570. flush-input  [Function]
  571.  
  572.     Arguments
  573.         stream :: <stream>
  574.     Values
  575.         none
  576.     Description
  577.         Flushes all pending input from stream, both buffered input and, if
  578.         possible, any that is available at stream's source. This function
  579.         returns no values.
  580.  
  581. force-output  [Function]
  582.  
  583.     Arguments
  584.         stream :: <stream>
  585.     Values
  586.         none
  587.     Description
  588.         Forces any pending output from stream's buffer to stream's
  589.         destination.  This function corresponds to forceoutput-buffer but
  590.         provides a higher-level interface for the more common situation
  591.         where the user does not hold the stream's output buffer. This
  592.         function returns no values.
  593.  
  594. synchronize-output  [Function]
  595.  
  596.     Arguments
  597.         stream :: <stream>
  598.     Values
  599.         none
  600.     Description
  601.         Forces any pending output from stream's buffer to stream's
  602.         destination.  This function also does whatever it can to ensure the
  603.         output reaches the stream's destination before returning, thereby
  604.         synchronizing the output destination with the application.  This
  605.         function essentially calls the functions get-output-buffer,
  606.         emptyoutputbuffer, force-secondary-buffers, and synchronize. See the
  607.         definition of synchronize for more information. This function
  608.         returns no values.
  609.  
  610. 4.2.  Data Extension Protocol
  611.  
  612. This subsection of the <stream> protocol describes the Data Extension
  613. Protocol.  These functions provide higher-level reading and writing
  614. operations, and they allow users to extend reading and writing to new
  615. classes of data objects.  The Data Extension Protocol typically specializes
  616. methods based on the classes of data objects returned by reading or accepted
  617. for writing. Sometimes these functions need to specialize on the stream as
  618. well as the data; for example, to most efficiently deliver a buffer to an
  619. output stream's destination, a method may need to be specific to a stream.
  620. This subsection describes the following functions:
  621.  
  622.     READ-AS
  623.     READ-INTO!
  624.     WRITE
  625.     WRITE-LINE
  626.  
  627. read-as  [Generic Function]
  628.  
  629.     Arguments
  630.         result-class :: <class>
  631.         stream :: <stream>
  632.         #key signal-eof? :: <boolean> = #t
  633.     Values
  634.         object :: union(<object>, singleton(#f))
  635.         eof? :: <object>
  636.     Description
  637.         Reads and returns an instance of result-class from stream. The
  638.         second return value indicates whether reading from stream
  639.         encountered the end of the stream's source. Methods of read-as may
  640.         take appropriate keywords to specify the constraints of the read.
  641.         This function blocks until it can complete the read specified.
  642.  
  643.         If reading from stream encounters the end of the stream, then the
  644.         signal-eof? argument determines the behavior of this function. If
  645.         signal-eof? is #t (the default), then this function signals an
  646.         <end-of-file> error (see Section Conditions); otherwise, it returns
  647.         #f and #t as multiple values.
  648.  
  649.         The read-as function differs from read-into! in that read-as makes
  650.         the object returned.
  651.  
  652. read-as  [Sealed Method]
  653.  
  654.     Arguments
  655.         result-class :: <byte>
  656.         stream :: <stream>
  657.         #key signal-eof? :: <boolean> = #t
  658.     Values
  659.         byte :: union(<byte>, singleton(#f))
  660.         eof? :: <boolean>
  661.     Description
  662.         Returns a byte from stream according to the description of the
  663.         read-as generic function.
  664.  
  665. read-as  [Sealed Method]
  666.  
  667.     Arguments
  668.         result-class :: <byte-character>
  669.         stream :: <stream>
  670.         #key signal-eof? :: <boolean> = #t
  671.     Values
  672.         char :: union(<byte-character>, singleton(#f))
  673.         eof? :: <boolean>
  674.     Description
  675.         Returns a byte-character from stream according to the description of
  676.         the read-as generic function.
  677.  
  678. read-as  [Method]
  679.  
  680.     Arguments
  681.         result-class :: one-of(<byte-string>, <byte-vector>, <buffer>)2
  682.         stream :: <stream>
  683.         #key signal-eof? :: <boolean> = #t
  684.         count :: <fixed-integer>
  685.         to-eof? :: <boolean> = #f
  686.     Values
  687.         result :: type-or(<byte-string>, <byte-vector>, <buffer>,
  688.         singleton(#f))3
  689.         eof?-or-how-much :: union(<boolean>, <fixed-integer>)
  690.     Description
  691.         Reads and returns an instance of result-class from stream according
  692.         to the description of the read-as generic function, with the noted
  693.         exceptions below. Implementations are required to provide sealed
  694.         methods for the result-class values.
  695.  
  696.         Supplying a count: argument specifies a required read. The argument
  697.         is the required size of the result. If this method cannot satisfy
  698.         the read request, then it regards signal-eof? according to the
  699.         description of the read-as generic function.
  700.  
  701.         Supplying the to-eof? argument as #t indicates the user wants to
  702.         read all the data available up to the end of the stream's source.
  703.         Supplying the to-eof? argument as #t effectively overrides the
  704.         signal-eof? argument. In this situation, this method always returns
  705.         an object of the requested type, and the second return value is
  706.         always the number of bytes read. The to-eof? behavior exists as a
  707.         convenience to support a style of reading on streams that do not
  708.         adhere to the Random Access Protocol; streams that do adhere to the
  709.         Random Access Protocol allow users to compute how much data remains
  710.         to be read.
  711.  
  712.         This function returns buffers to support users who need to perform
  713.         very big reads as efficiently as possible. Implementations should
  714.         support returning buffers as directly as possible, avoiding double
  715.         buffering or other unnecessary inefficiencies. Of course, any
  716.         pending input in the stream's buffer must be placed in the result
  717.         buffer as part of completing the read specified.
  718.  
  719. read-into!  [Generic Function]
  720.  
  721.     Arguments
  722.         destination :: <object>
  723.         stream :: <stream>
  724.         #key signal-eof? :: <boolean> = #t
  725.     Values
  726.         destination :: union(<object>, singleton(#f))
  727.         eof? :: <object>
  728.     Description
  729.         Fills in destination with input from stream. The second return value
  730.         indicates whether reading from stream encountered the end of the
  731.         stream's source. Methods of read-into! may take appropriate keywords
  732.         to specify the constraints of the read. This function blocks until
  733.         it can complete the read specified.
  734.  
  735.         If reading from stream encounters the end of the stream, then the
  736.         signal-eof? argument determines the behavior of this function. If
  737.         signal-eof? is #t (the default), then this function signals an
  738.         <end-of-file> error (see Section Conditions); otherwise, it returns
  739.         #f and #t as multiple values.
  740.  
  741. read-into!  [Method]
  742.  
  743.     Arguments
  744.         destination :: type-or(<byte-string>, <byte-vector>, <buffer>)3
  745.         stream :: <stream>
  746.         #key signal-eof? :: <boolean> = #t
  747.         start :: <fixed-integer> = 0
  748.         end :: <fixed-integer> = destination.size
  749.         to-eof? :: <boolean> = #f
  750.     Values
  751.         destination :: type-or(<byte-string>, <byte-vector>, <buffer>,
  752.         singleton(#f))
  753.         eof?-or-end :: union(<boolean>, <fixed-integer>)
  754.     Description
  755.         Fills in destination with input from stream according to the
  756.         description of the read-into! generic function, with the noted
  757.         exceptions below. Implementations are required to provide sealed
  758.         methods for the destination classes.
  759.  
  760.         When to-eof? is #f, the invocation specifies a required read. If
  761.         this method cannot satisfy the read request designated by start and
  762.         end,, then it regards signal-eof? according to the description of
  763.         the read-into! generic function.
  764.  
  765.         Supplying the to-eof? argument as #t indicates the user wants to
  766.         read all the data available up to the end of the stream's source.
  767.         Supplying the to-eof? argument as #t effectively overrides the
  768.         signal-eof? argument and the end argument. In this situation, this
  769.         method always returns destination, and the second return value is
  770.         always the end of the data read into destination. If the stream has
  771.         more than (destination.size - start) number of bytes available, then
  772.         this method signals an error. The to-eof? behavior exists as a
  773.         convenience to support a style of reading on streams that do not
  774.         adhere to the Random Access Protocol; streams that do adhere to the
  775.         Random Access Protocol allow users to compute how much data remains
  776.         to be read.
  777.  
  778.         This function takes a buffer to support users who need to perform
  779.         very big reads as efficiently as possible. Implementations should
  780.         support filling the argument buffer as directly as possible,
  781.         avoiding double buffering or other unnecessary inefficiencies. Of
  782.         course, any pending input in the stream's buffer must be placed in
  783.         the argument buffer as part of completing the read specified.
  784.  
  785. write  [Generic Function]
  786.  
  787.     Arguments
  788.         object :: <object>
  789.         stream :: <stream>
  790.         #key
  791.     Values
  792.         stream :: <stream>
  793.     Description
  794.         Writes object to stream. Methods of write may take appropriate
  795.         keywords to specify the constraints of the write.
  796.  
  797.         Note, because a sealed method for <byte> is required, users should
  798.         not extend this protocol to <integer>.  Another library will provide
  799.         more general and higher-level output functionality, such as printing
  800.         <integer> instances in a human readable format or printing strings
  801.         in a Dylan parse-able format.
  802.  
  803. write  [Sealed Method]
  804.  
  805.     Arguments
  806.         byte :: <byte>
  807.         stream :: <stream>
  808.     Values
  809.         stream :: <stream>
  810.     Description
  811.         Writes byte to stream.
  812.  
  813. write  [Sealed Method]
  814.  
  815.     Arguments
  816.         char :: <byte-character>
  817.         stream :: <stream>
  818.     Values
  819.         stream :: <stream>
  820.     Description
  821.         Writes char to stream.
  822.  
  823. write  [Method]
  824.  
  825.     Arguments
  826.         object :: type-or(<byte-vector>, <byte-string>, <buffer>)3
  827.         stream :: <stream>
  828.         #key start :: <fixed-integer> = 0
  829.         end :: <fixed-integer> = object.size
  830.     Values
  831.         stream :: <stream>
  832.     Description
  833.         Writes object to stream. Implementations are required to provide
  834.         sealed methods for the specified classes of object:.
  835.  
  836.         This function takes a buffer to support users who need to perform
  837.         very big writes as efficiently as possible. Implementations should
  838.         deliver the contents of the argument buffer as directly as possible
  839.         to the stream's destination, avoiding double buffering or other
  840.         unnecessary inefficiencies. Of course, any pending output in the
  841.         stream's buffer must be delivered to the stream's destination ahead
  842.         of the argument buffer.
  843.  
  844. write-line  [Generic Function]
  845.  
  846.     Arguments
  847.         object :: <object>
  848.         stream :: <stream>
  849.         #key
  850.     Values
  851.         stream :: <stream>
  852.     Description
  853.         Writes object to stream with the write function, and then writes a
  854.         newline character.  All keyword arguments are passed to the write
  855.         function.  Multi-threaded implementations should arrange for the
  856.         output of the write call on object and the newline to be contiguous.
  857.  
  858. 4.3.  Buffer Access Protocol
  859.  
  860. This subsection of the <stream> protocol describes the Buffer Access
  861. Protocol. These functions provide users the means to get and release input
  862. and output buffers, fill input buffers, force output buffers, and so on.
  863. Users should never add methods to these functions. This subsection describes
  864. the following functions:
  865.  
  866.     GET-INPUT-BUFFER
  867.     RELEASE-INPUT-BUFFER
  868.     FILL-INPUT-BUFFER
  869.     INPUT-AVAILABLE-AT-SOURCE?
  870.     GET-OUTPUT-BUFFER
  871.     RELEASE-OUTPUT-BUFFER
  872.     EMPTY-OUTPUT-BUFFER
  873.     FORCE-SECONDARY-BUFFERS
  874.     SYNCHRONIZE
  875.  
  876. These functions call their corresponding functions from the Stream Extension
  877. Protocol. For example, getinput-buffer calls
  878. stream-extension-get-input-buffer. Users always call the Buffer Access
  879. Protocol functions to operate on buffers directly, never the
  880. stream-extension- functions. Threaded Dylan implementations should place
  881. system-dependent mutual exclusion calls in the Buffer Access Protocol
  882. functions. The existence of these functions allows users to more portably
  883. extend the stream protocol to new streams.  Users avoid the following design
  884. and maintenance hassles:
  885.  
  886.   * Deciding whether to write for a threaded or a non-threaded Dylan
  887.     implementation.
  888.   * Rewriting mutual exclusion code for each Dylan implementation.
  889.   * Having to duplicate mutual exclusion code wherever the application uses
  890.     stream buffers directly.
  891.  
  892. Note, when Dylan has a macro facility, some of the Buffer Access Protocol
  893. will change. Instead of having separate functions to get and release
  894. buffers, there will be two macros, with-input-buffer and with-output-buffer.
  895.  
  896. get-input-buffer  [Function]
  897.  
  898.     Arguments
  899.         stream :: <stream>
  900.     values
  901.         buffer :: <buffer>
  902.         next :: <buffer-index>
  903.         end :: <buffer-index>
  904.     Description
  905.         Returns the input buffer for stream. See the definition of
  906.         stream-extension-get-input-buffer for details on the return values
  907.         and behavior of this function.
  908.  
  909.         If an application calls this function, and the application already
  910.         holds the input or output buffer for stream, then this function
  911.         might block.  Multi-threaded implementations should eventually
  912.         return.  All implementations are free to provide some form of
  913.         recovery for environmental reasons; for example, if the environment
  914.         is single-threaded, and users can cause the main stream of I/O to
  915.         block due to re-entrancy or whatever, then implementations are free
  916.         to detect this and take action to keep the environment accessible to
  917.         the users.
  918.  
  919. release-input-buffer  [Function]
  920.  
  921.     Arguments
  922.         stream :: <stream>
  923.         next :: <buffer-index>
  924.         end :: <buffer-index>
  925.     Values
  926.         none
  927.     Description
  928.         Announces that the user is done with stream's buffer and updates
  929.         stream's state relative to the buffer. See the definition of
  930.         stream-extension-get-input-buffer for details on the arguments. If
  931.         the application does not hold the buffer, this function signals an
  932.         error. This function returns no values.
  933.  
  934. fill-input-buffer  [Generic Function]
  935.  
  936.     Arguments
  937.         stream :: <stream>
  938.         start :: <buffer-index>
  939.     Values
  940.         end :: <buffer-index>
  941.     Description
  942.         Gets as much input as is available and that will fit in stream's
  943.         buffer from the start location to the buffer size.  Because stream
  944.         has no way to keep track of its buffer's state while users
  945.         manipulate the buffer directly, users must indicate where pending
  946.         input, if any, is in the buffer. The start argument serves this
  947.         purpose and provides users the flexibility to get more input while
  948.         leaving some pending input in the buffer.
  949.  
  950.         This function returns the end of the newly available input.  If no
  951.         input is available, this function blocks until some input is
  952.         available; however, when this function detects the end of the
  953.         stream's source, it returns zero instead of blocking.
  954.  
  955.         If the application does not hold stream's buffer, this function
  956.         signals an error.
  957.  
  958. input-available-at-source?  [Generic Function]
  959.  
  960.     Arguments
  961.         stream :: <stream>
  962.     Values
  963.         input-available? :: <boolean>
  964.     Description
  965.         Returns #t when stream's source has any available input or when the
  966.         stream is at the end of its source.  If this function returns #t,
  967.         then the next call to fill-input-buffer will not block.  If the
  968.         application does not hold stream's buffer, this function signals an
  969.         error.
  970.  
  971. get-output-buffer  [Function]
  972.  
  973.     Arguments
  974.         stream :: <stream>
  975.     Values
  976.         buffer :: <buffer>
  977.         next :: <buffer-index>
  978.         size :: <buffer-index>
  979.     Description
  980.         Returns the output buffer for stream. See the definition of
  981.         stream-extension-get-output-buffer for details on the return values
  982.         and behavior of this function.
  983.  
  984.         If an application calls this function, and the application already
  985.         holds the input or output buffer for stream, then this function
  986.         might block.  Multi-threaded implementations should eventually
  987.         return.  All implementations are free to provide some form of
  988.         recovery for environmental reasons; for example, if the environment
  989.         is single-threaded, and users can cause the main stream of I/O to
  990.         block due to re-entrancy or whatever, then implementations are free
  991.         to detect this and take action to keep the environment accessible to
  992.         the users.
  993.  
  994. release-output-buffer  [Function]
  995.  
  996.     Arguments
  997.         stream :: <stream>
  998.         next :: <buffer-index>
  999.     Values
  1000.         none
  1001.     Description
  1002.         Announces that the user is done with stream's buffer and updates
  1003.         stream's state relative to the buffer.  See the definition of
  1004.         stream-extension-get-input-buffer for details on the arguments. If
  1005.         the application does not hold the buffer, this function signals an
  1006.         error. This function returns no values.
  1007.  
  1008. empty-output-buffer  [Generic Function]
  1009.  
  1010.     Arguments
  1011.         stream :: <stream>
  1012.         end :: <buffer-index>
  1013.     Values
  1014.         none
  1015.     Description
  1016.         Forces out the contents of stream's buffer from location zero to
  1017.         end.  Because stream has no way to keep track of its buffer's state
  1018.         while users manipulate the buffer directly, users must indicate
  1019.         where the pending output is in the buffer. When this function
  1020.         returns, the user may begin placing more output in the buffer.
  1021.  
  1022.         If the application does not hold the buffer, this function signals
  1023.         an error.
  1024.  
  1025.         This function returns no values.
  1026.  
  1027. force-secondary-buffers  [Generic Function]
  1028.  
  1029.     Arguments
  1030.         stream :: <stream>
  1031.     Values
  1032.         none
  1033.     Description
  1034.         Forces any secondary buffering that a stream may have. It is rare
  1035.         that a stream would require secondary buffering, but a function that
  1036.         directly manipulates buffers and needs to force out all output must
  1037.         call both empty-output-buffer and force-secondary-buffers. Most
  1038.         streams applications will not call this function because most
  1039.         streams applications can call force-output.
  1040.  
  1041.         This function returns no values.
  1042.  
  1043. synchronize  [Generic Function]
  1044.  
  1045.     Arguments
  1046.         stream :: <stream>
  1047.     Values
  1048.         none
  1049.     Description
  1050.         Forces out the contents of stream's buffer from location zero to
  1051.         end.  This returns only when the buffer may be used further by the
  1052.         application. This function also does whatever it can to ensure the
  1053.         output reaches the stream's destination before returning, thereby
  1054.         synchronizing the output destination with the application.  For
  1055.         example, if stream delivered its output to an editor, calling
  1056.         empty-output-buffer and force-secondary-buffers would only require
  1057.         the stream to inject the output into the editor's text
  1058.         representation, but calling synchronize might cause the stream to
  1059.         invoke the editor's redisplay function.
  1060.  
  1061.         As another example, consider an empty-output-buffer implementation
  1062.         that copied the contents of a stream's buffer and queued the copy
  1063.         for output to the stream's destination, possibly because delivering
  1064.         that output is especially slow or may incur network overhead. The
  1065.         implementation of force-secondary-buffers should cause the queued
  1066.         output to appear at the stream's destination eventually, even if the
  1067.         application exits, but the implementation of synchronize should wait
  1068.         until the queue of output becomes empty and possibly even perform an
  1069.         extra handshake with the destination to ensure the output was
  1070.         received.
  1071.  
  1072.         If the application does not hold the buffer, this function signals
  1073.         an error.
  1074.  
  1075.         This function returns no values.
  1076.  
  1077. 4.4.  Stream Extension Protocol
  1078.  
  1079. This subsection of the <stream> protocol describes the Stream Extension
  1080. Protocol. These are the functions that users extend when defining new stream
  1081. subclasses:
  1082.  
  1083.     CLOSE
  1084.     STREAM-EXTENSION-GET-INPUT-BUFFER
  1085.     STREAM-EXTENSION-RELEASE-INPUT-BUFFER
  1086.     STREAM-EXTENSION-FILL-INPUT-BUFFER
  1087.     STREAM-EXTENSION-INPUT-AVAILABLE-AT-SOURCE?
  1088.     STREAM-EXTENSION-GET-OUTPUT-BUFFER
  1089.     STREAM-EXTENSION-RELEASE-OUTPUT-BUFFER
  1090.     STREAM-EXTENSION-EMPTY-OUTPUT-BUFFER
  1091.     STREAM-EXTENSION-FORCE-SECONDARY-BUFFERS
  1092.     STREAM-EXTENSION-SYNCHRONIZE
  1093.  
  1094. The make method for all stream classes takes a size: keyword argument that
  1095. suggests the buffer size that the user thinks will be best for the stream's
  1096. use. Users must still inspect the size returned when fetching the buffer
  1097. because they may not get the size requested.
  1098.  
  1099. close  [Generic Function]
  1100.  
  1101.     Arguments
  1102.         stream :: <stream>
  1103.     Values
  1104.         none
  1105.     Description
  1106.         Closes stream and potentially frees any resources backing it. If
  1107.         stream supports output, then this function forces any pending
  1108.         output. It is an error to call the close function on a stream while
  1109.         its buffer is held. This function returns no values.
  1110.  
  1111. stream-extension-get-input-buffer  [Generic Function]
  1112.  
  1113.     Arguments
  1114.         stream :: <stream>
  1115.     Values
  1116.         buffer :: <buffer>
  1117.         next :: <buffer-index>
  1118.         end :: <buffer-index>
  1119.     Description
  1120.         Returns the input buffer for stream. Users of a stream object never
  1121.         call this function; it exists only for users to extend the stream
  1122.         protocol to new stream subclasses. See the definition of
  1123.         get-input-buffer.
  1124.  
  1125.         This function also returns the stream's state relative to the
  1126.         buffer, which is the next available byte for input and the end of
  1127.         available bytes for input. The following diagram illustrates the
  1128.         additional return values:
  1129.  
  1130.                          +-----------------------------+
  1131.                 buffer:  | | | | | | | | | | | | | | | |
  1132.                          +-----------------------------+
  1133.                                     ^           ^
  1134.                                  next         end
  1135.  
  1136.         Consider a buffer that has input in it from the stream's source.  At
  1137.         any point the following is true:
  1138.  
  1139.           * The bytes contained between locations zero, inclusively, and
  1140.             next, exclusively, have already been consumed by some user of
  1141.             the stream.
  1142.           * The bytes contained between locations next, inclusively, and
  1143.             end, exclusively, have not been consumed by any user of the
  1144.             stream.
  1145.           * The bytes contained between locations end, inclusively, and the
  1146.             size of the buffer, exclusively, are undefined.
  1147.  
  1148.         This function may return a buffer with no available input; this is
  1149.         true when next == end.4
  1150.  
  1151.         If stream is an output only stream, then this signals an error. If
  1152.         the application already holds the buffer, then this function signals
  1153.         an error.
  1154.  
  1155. stream-extension-release-input-buffer  [Generic Function]
  1156.  
  1157.     Arguments
  1158.         stream :: <stream>
  1159.         next :: <buffer-index>
  1160.         end :: <buffer-index>
  1161.     Values
  1162.         none
  1163.     Description
  1164.         Announces that the user is done with stream's buffer and updates
  1165.         stream's state relative to the buffer.  Users of a stream object
  1166.         never call this function; it exists only for users to extend the
  1167.         stream protocol to new stream subclasses.  See the definition of
  1168.         release-input-buffer.
  1169.  
  1170.         Because stream has no way to keep track of its buffer's state while
  1171.         users manipulate the buffer directly, users must pass information
  1172.         back to stream to indicate where pending input, if any, is in the
  1173.         buffer. The next argument indicates the location of the first byte,
  1174.         if any, remaining to be read. The end argument indicates the end of
  1175.         any pending input in the buffer. See
  1176.         stream-extension-get-input-buffer for details on these values.
  1177.  
  1178.         This function returns no values.
  1179.  
  1180. stream-extension-fill-input-buffer  [Generic Function]
  1181.  
  1182.     Arguments
  1183.         stream :: <stream>
  1184.         start :: <buffer-index>
  1185.     Values
  1186.         end :: <buffer-index>
  1187.     Description
  1188.         Gets as much input as is available and that will fit in stream's
  1189.         buffer from the start location to the buffer size.
  1190.  
  1191.         This function returns the end of the newly available input.  If no
  1192.         input is available, this function blocks until some input is
  1193.         available; however, when this function detects the end of the
  1194.         stream's source, it returns zero instead of blocking.
  1195.  
  1196. stream-extension-input-available-at-source?  [Generic Function]
  1197.  
  1198.     Arguments
  1199.         stream :: <stream>
  1200.     Values
  1201.         input-available? :: <boolean>
  1202.     Description
  1203.         Returns #t when stream's source has any available input or when the
  1204.         stream is at the end of its source.  If this function returns #t,
  1205.         then the next call to stream-extension-fill-input-buffer will not
  1206.         block.
  1207.  
  1208. stream-extension-get-output-buffer  [Generic Function]
  1209.  
  1210.     Arguments
  1211.         stream :: <stream>
  1212.     Values
  1213.         buffer :: <buffer>
  1214.         next :: <buffer-index>
  1215.         end :: <buffer-index>
  1216.     Description
  1217.         Returns the output buffer for stream. Users of a stream object never
  1218.         call this function; it exists only for users to extend the stream
  1219.         protocol to new stream subclasses.  See the definition of
  1220.         get-output-buffer.
  1221.  
  1222.         This function also returns stream's state relative to the buffer,
  1223.         which is the next location available to place output and the size of
  1224.         the buffer (the end of available locations for placing output).  The
  1225.         following diagram illustrates the additional return values:
  1226.  
  1227.                          +-----------------------------+
  1228.                 buffer:  | | | | | | | | | | | | | | | |
  1229.                          +-----------------------------+
  1230.                                   ^                     ^
  1231.                                next                   end
  1232.  
  1233.         Consider a buffer that has pending output in it.  At any point the
  1234.         following is true:
  1235.  
  1236.           * The bytes contained between locations zero, inclusively, and
  1237.             next, exclusively, are pending output and need to be forced out
  1238.             to the stream's destination.
  1239.           * The bytes contained between locations next, inclusively, and
  1240.             end, exclusively, are undefined.
  1241.  
  1242.         This function never returns a full output buffer.
  1243.  
  1244.         If stream is an input only stream, then this signals an error.  If
  1245.         the application already holds the buffer, then this function signals
  1246.         an error.
  1247.  
  1248. stream-extension-release-output-buffer  [Generic Function]
  1249.  
  1250.     Arguments
  1251.         stream :: <stream>
  1252.         next :: <buffer-index>
  1253.     Values
  1254.         none
  1255.     Description
  1256.         Announces that the user is done with stream's buffer and updates
  1257.         stream's state relative to the buffer.  Users of a stream object
  1258.         never call this function; it exists only for users to extend the
  1259.         stream protocol to new stream subclasses.  See the definition of
  1260.         release-output-buffer.
  1261.  
  1262.         Because stream has no way to keep track of its buffer's state while
  1263.         users manipulate the buffer directly, users must pass information
  1264.         back to stream to indicate where pending output, if any, is in the
  1265.         buffer. The next argument indicates the end of the pending output,
  1266.         if any. See stream-extension-get-output-buffer for details on these
  1267.         values.
  1268.  
  1269.         This function returns no values.
  1270.  
  1271. stream-extension-empty-output-buffer  [Generic Function]
  1272.  
  1273.     Arguments
  1274.         stream :: <stream>
  1275.         end :: <buffer-index>
  1276.     Values
  1277.         none
  1278.     Description
  1279.         Forces out the contents of stream's buffer from location zero to
  1280.         end. When this function returns, the user may begin placing more
  1281.         output in the buffer.
  1282.  
  1283.         This function returns no values.
  1284.  
  1285. stream-extension-force-secondary-buffers  [Generic Function]
  1286.  
  1287.     Arguments
  1288.         stream :: <stream>
  1289.     Values
  1290.         none
  1291.     Description
  1292.         Forces any secondary buffering that stream may have. This function
  1293.         returns no values.
  1294.  
  1295. stream-extension-force-secondary-buffers  [Method]
  1296.  
  1297.     Arguments
  1298.         stream :: <stream>
  1299.     Values
  1300.         none
  1301.     Description
  1302.         This is the default method for
  1303.         stream-extension-force-secondary-buffers. It simply returns #f. This
  1304.         method is provided because most streams will not use secondary
  1305.         buffers, so most users who define new streams can avoid providing
  1306.         methods for this function.
  1307.  
  1308. stream-extension-synchronize  [Generic Function]
  1309.  
  1310.     Arguments
  1311.         stream :: <stream>
  1312.         end :: <buffer-index>
  1313.     Values
  1314.         none
  1315.     Description
  1316.         Forces out the contents of stream's buffer from location zero to
  1317.         end.  This returns only when the buffer may be used further by the
  1318.         application. This function also does whatever it can to ensure the
  1319.         output reaches the stream's destination before returning, thereby
  1320.         synchronizing the output destination with the application. This
  1321.         function returns no values. See the description of synchronize for
  1322.         more information.
  1323.  
  1324. 5.  The <random-access-stream> Protocol
  1325. ---------------------------------------
  1326. This section describes the following functions from the Streams module:
  1327.  
  1328.     STREAM-POSITION
  1329.     STREAM-POSITION-SETTER
  1330.     ADJUST-STREAM-POSITION
  1331.     STREAM-SIZE
  1332.  
  1333. Setting or adjusting an output stream's position to be at a location before
  1334. the end of the stream does not truncate the stream. The stream must support
  1335. overwriting of previous output.
  1336.  
  1337. stream-position  [Generic Function]
  1338.  
  1339.     Arguments
  1340.         stream :: <random-access-stream>
  1341.     Values
  1342.         position :: <integer>
  1343.     Description
  1344.         Returns stream's position for reading or writing as the offset from
  1345.         position zero. If the stream's buffer is held, then this function
  1346.         signals an error.
  1347.  
  1348. stream-position-setter  [Generic Function]
  1349.  
  1350.     Arguments
  1351.         position :: <integer>
  1352.         stream :: <random-access-stream>
  1353.     Values
  1354.         position :: <integer>
  1355.     Description
  1356.         Sets stream's position for reading or writing to be position.. If
  1357.         position is less than zero or greater than streamsize(stream), this
  1358.         function signals an error. If the stream's buffer is held, then this
  1359.         function signals an error.
  1360.  
  1361. adjust-stream-position  [Generic Function]
  1362.  
  1363.     Arguments
  1364.         offset :: <integer>
  1365.         stream :: <random-access-stream>
  1366.         #key from :: one-of(#"start", #"current", #"end")2 = #"start"
  1367.     Values
  1368.         position :: <integer>
  1369.     Description
  1370.         Sets stream's position for reading or writing to be offset from the
  1371.         from argument. This function returns the new absolute position in
  1372.         the stream. If the new absolute position is less than zero, then
  1373.         this function signals an error. If the new absolute position is
  1374.         greater than streamsize(stream), then this function extends the
  1375.         stream's size to equal the new position, and the bytes from the old
  1376.         size to the new size are filled with zeroes. If the stream's buffer
  1377.         is held, then this function signals an error.
  1378.  
  1379. stream-size  [Generic Function]
  1380.  
  1381.     Arguments
  1382.         stream :: <random-access-stream>
  1383.     Values
  1384.         size :: <integer>
  1385.     Description
  1386.         Returns the number of bytes in stream . For input streams, this is
  1387.         the number of bytes that were available when the stream was made.
  1388.         For output streams, this is the number of bytes that would be
  1389.         present at the stream's destination if the application were to
  1390.         synchronize output and close the stream. If the stream's buffer is
  1391.         held, then this function signals an error.
  1392.  
  1393. 6.  The <file-stream> Protocol
  1394. ------------------------------
  1395. The Streams library does not provide a general file system interface,
  1396. offering such operations as probing files, deleting files, renaming files,
  1397. querying file authors and write dates, and so on.  These kinds of operations
  1398. should be provided by a separate library.
  1399.  
  1400. When users instantiate the <file-stream> class, they get an
  1401. implementation-dependent indirect instance that is both a <filestream> and a
  1402. <random-access-stream>. The make method for <file-stream> and its subclasses
  1403. takes the following keywords:
  1404.  
  1405.     NAME:
  1406.         This parameter specifies the filename to open.  It must be a
  1407.         <string>.
  1408.     DIRECTION:
  1409.         This parameter specifies whether the stream will support input,
  1410.         output, or both operations.  It takes the following values:
  1411.  
  1412.         #"input"
  1413.             Results in an input stream.  This is the default.  If the file
  1414.             does not exist, then the make method signals a <file-not-found>
  1415.             error.
  1416.         #"output"
  1417.             Results in an output stream.
  1418.         #"input-output"
  1419.             Results in a stream that supports input an output operations.
  1420.  
  1421.     IF-EXISTS:
  1422.         This parameter specifies what action to take when direction: is
  1423.         #"output" or #"input-output", and the indicated file already exists.
  1424.         It takes the following values:
  1425.  
  1426.         #"signal"
  1427.             Signals a <file-exists> error.
  1428.         #"replace" (the default)
  1429.             Replaces the existing file with new output.
  1430.         #"overwrite"
  1431.             Opens the file such that output operations destructively modify
  1432.             the exiting file.  When specifying direction: as
  1433.             #"input-output", it is important to distinguish whether the
  1434.             system should truncate the file size to zero.  Specifying
  1435.             if-exists: as #"overwrite" preserves the existing contents of
  1436.             the file as opposed to #"replace". The file position will be at
  1437.             the start of the file.
  1438.         #"append"
  1439.             Opens the file such that output operations destructively modify
  1440.             the exiting file.  This is the same as #"overwrite", except that
  1441.             the file position will be at the end of the file.
  1442.  
  1443. 7.  The <string-input-stream> Protocol
  1444. --------------------------------------
  1445. The make method for <string-input-stream> takes a required string: keyword
  1446. argument. The make method also takes start: and end: keywords for the
  1447. string.  Reading starts at start:, and the stream signals <end-of-file> when
  1448. the user attempts to read past the exclusive end:.
  1449.  
  1450. 8.   The <string-output-stream> Protocol
  1451. ----------------------------------------
  1452. The <string-output-stream> class supports the following operation from the
  1453. Streams module:
  1454.  
  1455. string-output-stream-string  [Generic Function]
  1456.  
  1457.     Arguments
  1458.         stream :: <string-output-stream>
  1459.     Values
  1460.         output :: <string>
  1461.     Description
  1462.         Returns all the output accumulated in stream since the last call to
  1463.         string-output-stream-string.  If this function was never called on
  1464.         stream since the stream's creation, then this function returns all
  1465.         the output accumulated since the stream's creation. Implementations
  1466.         are required to provide a sealed method for <bytestringoutputstream>
  1467.         that returns a <byte-string>. If the stream's buffer is held, then
  1468.         this function signals an error.
  1469.  
  1470. 9.  The <buffer> Protocol
  1471. -------------------------
  1472. The <buffer> class is a sealed subclass of <vector>.  This section describes
  1473. the following generic functions from the Streams module:5
  1474.  
  1475.     BUFFER-SUBSEQUENCE
  1476.     COPY-FROM-BUFFER!
  1477.     COPY-INTO-BUFFER!
  1478.  
  1479. Implementations should provide very fast (machine-level) byte copying for
  1480. the required methods for these functions.
  1481.  
  1482. buffer-subsequence  [Generic Function]
  1483.  
  1484.     Arguments
  1485.         buffer :: <buffer>
  1486.         result-class :: <class>
  1487.         start :: <buffer-index>
  1488.         end :: <buffer-index>
  1489.     Values
  1490.         result :: <sequence>
  1491.     Description
  1492.         Returns an instance of result-class using the elements from buffer
  1493.         between start, inclusively, and end, exclusively.  Implementations
  1494.         are required to provide sealed methods for the following
  1495.         result-class values:
  1496.  
  1497.         <BYTE-STRING>
  1498.         <BYTE-VECTOR>
  1499.         <BUFFER>
  1500.  
  1501.         It is an error to call this function with start or end values
  1502.         outside of range(from: 0, through: size(buffer)).
  1503.  
  1504. copy-from-buffer!  [Generic Function]
  1505.  
  1506.     Arguments
  1507.         destination :: <sequence>
  1508.         buffer :: <buffer>
  1509.         buffer-start :: <buffer-index>
  1510.         #key start :: <fixed-integer> = 0
  1511.         end :: <fixed-integer> = destination.size
  1512.     Values
  1513.         none
  1514.     Description
  1515.         Fills destination from start (defaults to zero) to end (defaults to
  1516.         the size of destination) with data from buffer that is taken
  1517.         starting at buffer-start.  Implementations are required to provide
  1518.         sealed methods for the following destination classes:
  1519.  
  1520.         <BYTE-STRING>
  1521.         <BYTE-VECTOR>
  1522.         <BUFFER>
  1523.  
  1524.         It is an error to call this function such that any attempt to index
  1525.         destination or buffer is out of bounds.  It is an error to call this
  1526.         function such that it attempts to index buffer elements in undefined
  1527.         ranges, as determined by the return values from get-input-buffer. It
  1528.         is an error for destination and buffer to be the same object. This
  1529.         function returns no values.
  1530.  
  1531. copy-into-buffer!  [Generic Function]
  1532.  
  1533.     Arguments
  1534.         source :: <sequence>
  1535.         buffer :: <buffer>
  1536.         buffer-start :: <buffer-index>
  1537.         #key start :: <fixed-integer> = 0
  1538.         end :: <fixed-integer> = source.size
  1539.     Values
  1540.         none
  1541.     Description
  1542.         Fills buffer starting at buffer-start with elements taken from
  1543.         source from start (defaults to zero) to end (defaults to the size of
  1544.         source). Implementations are required to provide sealed methods for
  1545.         the following classes:
  1546.  
  1547.         <BYTE-STRING>
  1548.         <BYTE-VECTOR>
  1549.         <BUFFER>
  1550.  
  1551.         It is an error to call this function such that any attempt to index
  1552.         source or buffer is out of bounds. It is an error for destination
  1553.         and buffer to be the same object. This function returns no values.
  1554.  
  1555. 10.  Locking Protocol
  1556. ---------------------
  1557. Stream locks have multilocking semantics. A single thread may repeatedly
  1558. lock a particular stream, but that thread must unlock the stream once for
  1559. each time it locked the stream. This allows a high-level printing routine to
  1560. lock a stream across several calls to output functions, ensuring all the
  1561. output is contiguous at the stream's destination. For example, the
  1562. write-line function locks its stream argument and then calls the write
  1563. function twice. The write function locks its stream argument by calling
  1564. get-output-buffer, but because of the multilocking semantics, the call to
  1565. write within write-line does not block waiting for a lock. Before returning,
  1566. write-line unlocks the stream so that other routines may call output
  1567. functions on the stream or get the stream's buffer for direct manipulation.
  1568.  
  1569. Note, when Dylan has a macro facility, the Locking Protocol will change.
  1570. Instead of having separate functions to lock and unlock streams, there will
  1571. be a macros, with-locked-stream.
  1572.  
  1573. The Streams module exports the following locking functions:
  1574.  
  1575. lock-stream  [Function]
  1576.  
  1577.     Arguments
  1578.         stream :: <stream>
  1579.     Values
  1580.         none
  1581.     Description
  1582.         Returns after successfully locking the stream. A single thread may
  1583.         successfully call this function repeatedly, but the thread must call
  1584.         unlock-stream once for each call to lock-stream. If the thread calls
  1585.         unlock-stream fewer times than lock-stream, the stream remains
  1586.         locked, and any threads waiting to lock the stream will continue to
  1587.         wait. When a thread that does not hold the stream's lock calls
  1588.         lock-stream, lock-stream puts the calling thread to sleep until the
  1589.         lock is available.
  1590.  
  1591.         In singlethreaded Dylan implementations, this function does nothing.
  1592.  
  1593. unlock-stream  [Function]
  1594.  
  1595.     Arguments
  1596.         stream :: <stream>
  1597.     Values
  1598.         none
  1599.     Description
  1600.         Releases the stream's lock. If the stream is already unlocked, this
  1601.         function signals an error. Only the thread that has the stream
  1602.         locked may call this function, and if another thread tries to unlock
  1603.         the stream, this function signals an error. When unlock-stream
  1604.         returns, the stream may still be locked. A thread that has
  1605.         repeatedly locked the stream, must call unlock-stream once for each
  1606.         call to lock-stream.
  1607.  
  1608.         In singlethreaded Dylan implementations, this function does nothing.
  1609.  
  1610. stream-locked?  [Function]
  1611.  
  1612.     Arguments
  1613.         stream :: <stream>
  1614.     Values
  1615.         locked? :: <boolean>
  1616.     Description
  1617.         Returns whether the stream is locked. In singlethreaded Dylan
  1618.         implementations, this function always returns #f.
  1619.  
  1620. 11.  Conditions
  1621. ---------------
  1622. The Streams module exports the following condition names and accessors:
  1623.  
  1624. <END-OF-FILE>
  1625.  
  1626.         The <end-of-file> condition is a subclass of <error>.  The recovery
  1627.         protocol is empty.  The make method takes the stream: keyword
  1628.         argument and stores the value in the condition object. The
  1629.         end-of-file-stream function when called on an <end-of-file> instance
  1630.         returns the value passed as the stream: argument to make. The stream
  1631.         object can be useful when reporting the condition to a user or
  1632.         distinguishing which stream ended when reading from more than one
  1633.         stream at a time.
  1634.  
  1635. <FILE-NOT-FOUND>
  1636.  
  1637.         The <file-not-found> condition is a subclass of <error>.  The
  1638.         recovery protocol is empty. The make method for <file-not-found>
  1639.         takes the filename: keyword argument and stores the value in the
  1640.         condition object.  The file-not-found-filename function when called
  1641.         on a <file-not-found> instance returns the value passed as the
  1642.         filename: argument to make.
  1643.  
  1644. <FILE-EXISTS>
  1645.  
  1646.         The <file-exists> condition is a subclass of <error>.  The recovery
  1647.         protocol is empty.  The make method takes the filename: keyword
  1648.         argument and stores the value in the condition object.  The
  1649.         file-exists-filename function when called on a <file-exists>
  1650.         instance returns the value passed as the filename: argument to make.
  1651.  
  1652. 12.  Footnotes
  1653. --------------
  1654.  
  1655.  1. The definition of read-line is contingent on Dylan's resolution of
  1656.     handling newlines, and this function may have problems on some systems.
  1657.  2. One-of returns a type expression that represents exactly the values
  1658.     passed in:
  1659.  
  1660.             define constant one-of =
  1661.               method (value, #rest more-values) => type :: <type>;
  1662.                 reduce(union, singleton(value), map(singleton, more-values));
  1663.               end method;
  1664.  
  1665.  3. Type-or returns a type expression that represents the union of all types
  1666.     passed in:
  1667.  
  1668.             define constant type-or =
  1669.               method (type :: <type>, #rest more-types) => type :: <type>;
  1670.                 // Ensure more-types contains only types.
  1671.                 do(rcurry(check-type, <type>), more-types);
  1672.                 // Make a union of all types out of Dylan's binary union function.
  1673.                 reduce(union, type, more-types);
  1674.               end method;
  1675.  
  1676.  4. The stream-extension-get-input-buffer function cannot guarantee to
  1677.     return a buffer with available input. Implementations will define the
  1678.     inputavailable? function in terms of checking the stream's buffer, and
  1679.     upon finding no available input there, then calling
  1680.     input-available-at-source?.  If stream-extension-get-input-buffer
  1681.     guaranteed returning a buffer with input available, then it might block
  1682.     getting that input. If stream-extension-get-input-buffer could block,
  1683.     then inputavailable? could not be defined in terms of the Stream
  1684.     Extension Protocol.
  1685.  5. We need these functions so that users can have reasonable semantics for
  1686.     copying to and from buffers.  There will likely be problems when
  1687.     implementations want to support <unicode-string> because copying
  1688.     unicode-string elements will take two buffer elements for each
  1689.     unicode-string element.  Ignoring extended character classes,
  1690.     copy-sequence and replace-sequence! have problems.  Using copy-sequence
  1691.     requires wrapping the as function around each call, and users have to
  1692.     hope their Dylan implementation does the right data flow analysis and
  1693.     source-level transforms to extract a sequence and create the right
  1694.     result type with exactly one allocation and one copying of the data.  If
  1695.     copy-sequence took a result class, then users could assume this would
  1696.     happen in one action. Using replace-sequence! has weird growth semantics
  1697.     which is inconsistent with this proposal's refusal to allow users to
  1698.     arbitrarily grow and replace a stream's buffer; this could be confusing
  1699.     to some users.  For example, users are surprisingly always baffled when
  1700.     they use Common Lisp's delete function, remove the first element of a
  1701.     list, and then cannot figure out why the result is not eq to the
  1702.     argument (even though the documentation always warned against this
  1703.     assumption).
  1704.